<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" href="css/plugins/sweetalert/sweetalert2.css">
    <link rel="stylesheet" href="css/bootstrap-table.css">
</head>
<style>
    .middle-box{
        max-width: 400px;
    }
</style>
<body>
<div class="container middle-box">
    <div class="row">
        <form role="form" class="form-horizontal" id="form">
            <div class="form-group">
                <label class="control-label col-sm-4">原密码：</label>
                <div class="col-sm-8"><input id="oldPassword"name="oldPassword" type="password" class="form-control" required></div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-4">新密码：</label>
                <div class="col-sm-8"><input id="newPassword"name="newPassword" type="password" class="form-control" required></div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-4">确认密码：</label>
                <div class="col-sm-8"><input id="confirm_psw" name="confirm_psw" type="password" class="form-control" required></div>
            </div>
            <button type="button" class="btn btn-primary col-sm-offset-7" onclick="save()">确定</button>
        </form>
    </div>
</div>


<script src="lib/jquery.min.js?v=2.1.4"></script>
<script src="lib/bootstrap.min.js?v=3.3.6"></script>
<script src="lib/plugins/validate/jquery.validate.min.js"></script>
<script src="lib/plugins/validate/messages_zh.min.js"></script>
<script src="lib/mes/public/publicURL.js"></script>
<script src="lib/plugins/sweetalert/sweetalert2.js"></script>
<script src="js/publicUrl.js"></script>
<script>
    $(function () {
        let icon = "<i class='fa fa-times-circle'></i>  ";
        $("#form").validate({
            rules:{
                confirm_psw:{
                    required:true,
                    equalTo:"#newPassword"
                }
            },
            messages:{
                confirm_psw:{
                    equalTo:icon+"两次输入的密码不一致"
                }
            }
        })
    });
    function save() {
        if ($("#form").valid()) {
        	console.log(sessionStorage.getItem("workNum"));
        	console.log($("#newPassword").val());
            $.ajax({
                url:url,
                dataType:"json",
                type: 'post',
                data:{
                    method:"modifyPassword",
                    username: sessionStorage.getItem("workNum"),
                    originPwd:$("#oldPassword").val(),
                    newPwd:$("#newPassword").val()
                },
                success:function (data) {
                    if(data.code===1){
                      swal(
                          data.msg,
                          '',
                          'info'
                      );
                    }
                    else if (data.code === 0) {
                      swal(
                          '修改成功',
                          '',
                          'success'
                      ).then(function(isConfirm) {
                        if (isConfirm) {
                          window.parent.location.href="login.html"
                        }
                      });
                    }
                },
            })
        }
    }
</script>
</body>
</html>